#include <iostream>
#include <vector>
using namespace std;

// 状态方程式： max( dp[ i ] ) = getMax( max( dp[ i -1 ] ) + arr[ i ] ,arr[ i ] )

int main()
{
    int n;
    cin >> n;
    vector<int> arr(n);
    for(size_t i = 0; i < n; ++i)
        cin >> arr[i];
    int sum = arr[0];
    int retMax = arr[0];
    for(size_t i = 1; i < n; ++i){
        sum = max(sum+arr[i], arr[i]);
        retMax = retMax>sum ? retMax : sum;
    }
    cout << retMax << endl;
    return 0;
}